package com.eqdd.yiqidian.ui.mine.shenqing;

import android.databinding.DataBindingUtil;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.ShowChuchaiActivityCustom;
import com.eqdd.yiqidian.adapter.MyFragmentPagerAdapter;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.bean.TabEntity;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

public class ShowChuchaiActivity extends BaseActivity {
    private ShowChuchaiActivityCustom dataBinding;
    private List<String> titles = new ArrayList<>();

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_show_chuchai);
        initTopTitleBar(View.VISIBLE, "出差列表");
        initTopRightImage(R.mipmap.add, v -> {

            startActivity(ApplyChuchaiActivity.class);
        });
    }

    @Override
    public void initData() {
        titles.add("申请中");
        titles.add("已通过");
        titles.add("未通过");
    }

    @Override
    public void setView() {

        ShenqingFragment applyFragment = new ShenqingFragment();
        ShenqingFragment passFragment = new ShenqingFragment();
        ShenqingFragment faildFragment = new ShenqingFragment();
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(applyFragment);
        fragments.add(passFragment);
        fragments.add(faildFragment);
        ArrayList<CustomTabEntity> customTabEntities = new ArrayList<>();
        for (int i = 0; i < titles.size(); i++) {
            TabEntity tabEntity = new TabEntity(titles.get(i), 0, 0);
            customTabEntities.add(tabEntity);
        }

        dataBinding.viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), titles, fragments));
        dataBinding.commonTabLayout.setTabData(customTabEntities);
        dataBinding.commonTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                dataBinding.viewPager.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        dataBinding.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                                                          @Override
                                                          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                                                          }

                                                          @Override
                                                          public void onPageSelected(int position) {
                                                              dataBinding.commonTabLayout.setCurrentTab(position);
                                                          }

                                                          @Override
                                                          public void onPageScrollStateChanged(int state) {

                                                          }
                                                      }
        );
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }
}
